import { Message } from 'element-ui'

export default function ({ $axios, redirect }) {
    //onError请求错误拦截器
    $axios.onError(err => {
        console.log(err);

        const { statusCode, message } = err.response.data

        if (statusCode === 401 || statusCode == 403) {
            Message.warning({ message: '请先登录' })
            redirect('/user/login')
        }

        if (statusCode === 400) {
            Message.warning({ message })
        }
    })

}

//全局挂在moment
import vue from 'vue'
import moment from 'moment'
vue.prototype.$moment = moment
